<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>审核管理</title>
    <link rel="stylesheet" type="text/css" href="../assets/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="../assets/fonts/line-icons.css">
    <link rel="stylesheet" type="text/css" href="../assets/css/main.css">
    <link rel="stylesheet" type="text/css" href="../assets/css/responsive.css">
	<link rel="stylesheet" type="text/css" href="../assets/plugins/datatables/bootstrap-table.min.css" />
</head>
<body>
<div class="container-fluid">
	<div class="breadcrumb-wrapper row">
		<div class="col-12 col-lg-3 col-md-6">
			<h4 class="page-title">用户审核</h4>
		</div>
		<div class="col-12 col-lg-9 col-md-6">
			<ol class="breadcrumb float-right">
				<li class="active">审核管理</li>
				<li class="active"> / 用户审核</li>
			</ol>
		</div>
	</div>
</div>
<div class="container-fluid">
	<div class="row">
		<div class="col-12">
			<div class="card">
				<div class="card-body">
					<form class="form-inline">
						<div class="col-10">
							<div class="form-group row">
								<label>查找用户：</label>
								<input type="text" class="form-control mb-2 mr-sm-2" id="findUsername" placeholder="账号"/>
								<input type="text" class="form-control mb-2 mr-sm-2" id="findSchool" placeholder="学校"/>
								<input type="text" class="form-control mb-2 mr-sm-2" id="findFaculty" placeholder="学院"/>
								<input type="text" class="form-control mb-2 mr-sm-2" id="findClass" placeholder="班级"/>
								<input type="button" class="btn btn-success" id="findUser" value="查找">
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="container-fluid">
	<table id="table">

	</table>
</div>
<script src="../assets/js/jquery-min.js"></script>
<script src="../assets/js/bootstrap.min.js"></script>
<script src="../assets/plugins/datatables/bootstrap-table.min.js"></script>
<script src="../assets/plugins/datatables/bootstrap-table-zh-CN.min.js"></script>
<script>
    //项目根路径
    var ctx = window.parent.ctx;
	var user = window.parent.user;
	var par = $("body");
	var pheight = $(window.parent.document).find(".main-content").height();
    
	$(function(){
		$.ajax({
			type: "post",
			url: ctx+"/user/findAuditUser",
			xhrFields: {
				withCredentials: true
			},
			data: {isPass: '0'},
			success: function(data) {
				$("#table").bootstrapTable('load', data);
				// 父页面自适应子页面高度
				par.height(pheight);
			}
		});
		
		$("#findUser").click(function(){
			$.ajax({
				type: "post",
				url: ctx+"/user/findAuditUserByEntity",
				xhrFields: {
					withCredentials: true
				},
				data: {username:$("#username").val(),school: $("#findSchool").val(),faculty:$("#findFaculty").val(),userClass:$("#findClass").val(),isPass:'0'},
				success: function(data){
					$("#table").bootstrapTable('load', data);
					// 父页面自适应子页面高度
					par.height(pheight);
				}
			});
		});

		$("#table").bootstrapTable({
			pagination: true,
			pageSize: 8,
			pageNumber: 1,
			smartDisplay: true,
			columns: [{
				field: '',
				title: '序号',
				formatter: function(value,row,index){
					return index+1;
				}
			},
				{
					field: 'username',
					title: '账号(学号，职工号)'
				},
				{
					field: 'nickname',
					title: '昵称'
				},
				{
					field: 'sex',
					title: '性别'
				},
				{
					field: 'school',
					title: '学校'
				},
				{
					field: 'faculty',
					title: '学院'
				},
				{
					field: 'userClass',
					title: '班级'
				},
				{
					field: 'role',
					title: '权限',
					formatter: function (value, row) {
						if(value===0){
							return "学生";
						}else if(value===1){
							return "老师";
						}else if(value===2){
							return "管理员";
						}
					}
				},
				{
					field: 'operate',
					title: '操作',
					events: {
						'click #pass': function (e, value, row) {
							isPass(row.id,'1');
						},
						'click #notPass': function (e, value, row) {
							isPass(row.id,'2');
						}
					},
					formatter: function(){
						var buttonStr = "<button id='pass' type='button' class='btn btn-success'>通过</button> "+
								"<button id='notPass' type='button' class='btn btn-danger'>不通过</button>"
						return buttonStr;
					}
				}],
			onPostBody: function () {
				$(".page-list").remove();
			}
		});

		function isPass(i,p){
			$.ajax({
				type: "post",
				url: ctx + "/user/editAuditUser",
				xhrFields: {
					withCredentials: true
				},
				data: {id: i,isPass:p},
				success: function(data){
					alert("修改成功");
					window.location.reload();
				}
			});
		}
	});
	
</script>
</body>
</html>